var _pInfo = {
	"walletUrl": null,
	"userInfo": null,
	"mywalletInfo": null,
	"param": getQueryParams(),
	"renderData": function() {
		AjaxRequest({
			url: _url + "/money/wallet/mywallet",
			type: "post",
			load: true,
			async: false,
			data: {
				"userid": _pInfo.userInfo["id"]
			},
			success: function(rs) {
				if(isReqSucceed(rs)) {
					_pInfo.mywalletInfo = rs.data;
					$("#wallet-content").html(template("wallet-content-tpl", {
						type: _pInfo.param.type,
						rs: rs.data
					}));
				}
			}
		});
	},
	"countMoney": function(o) {
		$("#countRes").val($(o).val());
	},
	"doWithdraw": function() {
		var reg = /^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/;
		var withDrawVal = $("#withDrawVal").val().trim();
		var callbackVal = $("#callbackVal").val().trim();
		if(!reg.test(withDrawVal)) {
			$.toast("提现金额必须是非负数", "text");
			return;
		}
		if(isNull(callbackVal)) {
			$.toast("请选择收款区块链钱包", "text");
			return;
		}
		$("#pwd-popup").popup();
	},
	"submitData": function() {
		var _safetyPasswd = $("#popup-ipt").val().trim();
		if(isNull(_safetyPasswd)) {
			$.toast("请输入资金密码", "text");
			return;
		}
		if(_safetyPasswd.length < 6) {
			$.toast("资金密码必须为6位数", "text");
			return;
		}
		if(isNaN(_safetyPasswd)) {
			$.toast("资金密码必须是纯数字", "text");
			return;
		}
		var _data = {
			"userid": _pInfo.userInfo["id"],
			"safetyPasswd": _safetyPasswd
		}
		AjaxRequest({
			url: _url + "/money/wallet/paypwdproving",
			type: "post",
			load: true,
			data: _data,
			success: function(rs) {
				if(isReqSucceed(rs)) {
					AjaxRequest({
						url: _url + "/money/wallet/drawmoney",
						type: "post",
						load: true,
						data: {
							"userid": _pInfo.userInfo["id"],
							"money": $("#withDrawVal").val().trim(),
							"walletUrl": _pInfo["walletUrl"]
						},
						success: function(rs) {
							if(isReqSucceed(rs)) {
								$.alert("提现成功", function() {
									window.location.href = "wallet-detail.html?type=0";
								});
							}
						}
					});
				}
			}
		});
	},
	"loadEvents": function() {
		_pInfo.userInfo = _user.getUserInfo();
		$("#slider").slider(function(val) {
			$("#slider-value").text(val + " gwei");
		});
	},
	"load": function() {
		this.loadEvents();
		this.renderData();
	}
}
exposeGlobalMethods({
	"countMoney": function(o) {
		_pInfo.countMoney(o);
	},
	"doWithdraw": function() {
		_pInfo.doWithdraw();
	},
	"submitData": function() {
		_pInfo.submitData();
	}
});
$(function() {
	_pInfo.load();
});

function getWalletUrl(walletUrl) {
	_pInfo["walletUrl"] = walletUrl;
	$("#callbackVal").val(walletUrl);
}